import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/',
    component: () => import('@h5/views/home.vue'),
    hidden: true,
  },
  {
    path: '/login',
    component: () => import('@h5/views/login.vue'),
    hidden: true,
  },
  {
    path: '/contracts',
    component: () => import('@h5/views/contracts.vue'),
    hidden: true,
  },
  {
    path: '/sendRecord',
    component: () => import('@h5/views/sendRecord.vue'),
    hidden: true,
  },
  {
    path: '/person',
    component: () => import('@h5/views/person.vue'),
    hidden: true,
  },
  {
    path: '/contractIframe',
    component: () => import('@h5/views/contractIframe.vue'),
    hidden: true,
  },
  {
    path: '/transitionPage',
    component: () => import('@h5/views/transitionPage.vue'),
    hidden: true,
  },
  // { path: '*', redirect: '/404', hidden: true },
];

const createRouter = () =>
  new Router({
    base: '/m',
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
    mode: 'history',
  });

const router = createRouter();

router.beforeEach((to, from, next) => {
  // console.log('to => ', to);
  // console.log('from => ', from);
  next();
});

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
